-
-
Notifications
You must be signed in to change notification settings - Fork 828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(git): Add bcommits_range picker #2398
feat(git): Add bcommits_range picker #2398
Conversation
5812136
to
ed6e964
Compare
What do you think about just having a separate picker for this rather than overriding the original? For example, we could have |
A separate picker sounds good to me. That would make it possible to define an operator-pending keymap for that picker. For example, I could type Otherwise, |
I pushed a commit with a separate |
de717f6
to
6f8b9b2
Compare
I pushed a commit which adds operator mode as an option, and it works as expected. For example, |
6f8b9b2
to
bd257b7
Compare
Love the operator pending stuff -- my only thought is that do you think it's possible to maybe move the operator pending logic outside of this function? Perhaps we can make a new module What are your thoughts on that? |
07227cd
to
86d76e2
Compare
That sounds good. I've updated the PR to move the operators functionality to |
24be9dc
to
77b4c4a
Compare
vim.o.operatorfunc = "v:lua.require'telescope.operators'.operator_callback" | ||
-- feed g@ to enter operator-pending mode | ||
-- 'i' required for which-key compatibility, etc. | ||
vim.api.nvim_feedkeys("g@", "mi", false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think after running this line we should clear the operator? Or perhaps on line 7? This way we drop the reference to the picker and it can be garbage collected later, which seems like a good idea.
Maybe it should be:
operators.operator_callback = function()
last_operator.callback(last_operator.opts)
last_operator = { callback = function(_) end, opts = {} }
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I tried something like that, but it breaks the key g@
to re-run the last operator. Not sure if that's a big deal or not as I don't use that keymap, but I didn't see a huge reason to break it.
How important is it to garbage collect the picker reference and opts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that makes sense.
It is kind of important, but it should be alright cause there is at most one outstanding, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it's only a reference to the most recent picker/callback function used with operators.run_operator
. At least for this picker it would just keep a reference to git.bcommits_range
and its opts.
1ede67a
to
2da39c3
Compare
By the way, what do you think about the names of the arguments to specify the range? I'd originally used edit: I will keep |
Starts operator-pending mode and shows commits in the range of lines covered by the next text object or motion
Can't use start/end, since end is an annoying keyword to use in lua and start/stop doesn't fit as well
Instead of calling bcommits
Default to a no-op callback
2da39c3
to
9dc1af6
Compare
I've rebased this PR on master to include the changes in #2597. |
Thanks for sticking with this^^ |
Maybe |
|
Beautiful. Thanks again 👍 |
Thanks for reviewing! |
Description
fzf.vim has a feature where the
:BCommits
command shows only commits affecting the selected lines, if run from visual mode.This functionality cannot be replicated in telescope with config options alone. Fzf.vim uses the arguments
git log --no-patch -L start,end:file
, which are not compatible with the filename that telescope appends togit_commands
. (I tried some hacks like adding an argument togit_commands
to make git ignore the filename argument, but they didn't work).Type of change
This PR only affects bcommits behavior when run in visual mode, so I think it's a minor change but could be considered breaking.This PR adds
bcommits_range
to show commits affecting a range of lines.bcommits_range
can get the range of selected lines in visual mode, and supports an operator-pending mode to get lines from the next text object or motion. To support operators, this PR also adds a newtelescope.operators
module.How Has This Been Tested?
bcommits_range
picker. Only commits affecting the selected lines should be shown. Check all previewer outputs to make sure they make sense.bcommits_range
in normal mode, all commits for the file should be shown.<cmd>Telescope git_bcommits_range first=1 last=10<CR>
in normal mode. Commits affecting the first 10 lines should be shown.<cmd>Telescope git_bcommits_range operator=true<CR>
in normal mode followed by a motion or text object, e.g.ip
for inner paragraph. All commits affecting the selected range should be shown.Configuration:
Notes
__git.lua
, not sure if that's ok, or if there's a better way to detect visual mode.Checklist: